package cn.zmit.kuxi.holder;

import java.util.List;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import cn.zmit.kuxi.R;
import cn.zmit.kuxi.contants.Url;
import cn.zmit.kuxi.entity.OldShareEntity;
import cn.zmit.kuxi.image.ImageDisplayer;
import cn.zmit.kuxi.interfaces.OnListItemSelectListener;
import cn.zmit.kuxi.request.RequestTask;

import com.xdroid.functions.holder.ViewHolderBase;

/** * @author chenxu @parameter * @return */
public class OldShareHolder extends ViewHolderBase<OldShareEntity> {
	private TextView title, goodsName, evaluate, time, phone;
	private LinearLayout llRoot, llPic;
	private Context context;
	public static OnListItemSelectListener<OldShareEntity> onlistItemSelect;

	@Override
	public View createView(LayoutInflater layoutInflater) {
		context = layoutInflater.getContext();
		View view = layoutInflater.inflate(R.layout.item_old_share_order, null);
		title = (TextView) view.findViewById(R.id.tv_old_title);
		goodsName = (TextView) view.findViewById(R.id.tv_title_data);
		evaluate = (TextView) view.findViewById(R.id.tv_oldGetWin);
		time = (TextView) view.findViewById(R.id.tv_title_time);
		phone = (TextView) view.findViewById(R.id.tv_oldShare_getWin);
		llRoot = (LinearLayout) view.findViewById(R.id.llRoot);
		llPic = (LinearLayout) view.findViewById(R.id.ll_pic);
		return view;
	}

	@Override
	public void showData(final int position, final OldShareEntity itemData) {
		llPic.removeAllViews();
		title.setText("第" + itemData.getTitle() + "期");
		goodsName.setText(itemData.getGoods_name());
		phone.setText("获奖用户："
				+ itemData.getPhone());
		evaluate.setText("晒单感言：" + itemData.getEvaluate());
		time.setText(itemData.getTime());
		llRoot.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if (onlistItemSelect != null) {
					onlistItemSelect.onlistItemSelect(position, itemData);
				}
			}
		});

		List<String> imageUrl = itemData.getImageURLEntities();
		if (imageUrl != null && imageUrl.size() > 0) {
			llPic.setVisibility(View.VISIBLE);
			for (int i = 0; i < imageUrl.size(); i++) {// 根据获取的的url动态生成ImageView
				ImageView imageView = new ImageView(context);
				imageView.setBackgroundResource(R.drawable.ic_launcher);
				LinearLayout ll = new LinearLayout(context);
				LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
						150, 150);
				params.setMargins(10, 10, 10, 10);// 设置间距
				imageView.setLayoutParams(params);
				ImageDisplayer.getInstance().dispalyImageWithRadius(
						Url.IMAGE_PIC_ROOT + imageUrl.get(i), imageView, 0);
				ll.addView(imageView);
				llPic.addView(ll);
			}
		} 
	}

	// 设置回调
	public static void setOnListItemSelectListener(
			OnListItemSelectListener<OldShareEntity> onListItemSelectListener) {
		OldShareHolder.onlistItemSelect = onListItemSelectListener;
	}
}
